package com.bfmet.metal;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;

import com.bfmet.common.base.DAOWrapper;
import com.bfmet.entity.Metal;
import com.bfmet.entity.News;

@ManagedBean
public class MetalAction extends DAOWrapper {

	public List<Metal> getMetalList() {
		List<Metal> list = new ArrayList<Metal>();
		for (Metal.Type type : Metal.Type.values()) {
			Metal metal = new Metal();
			metal.setName(type.getCnName());
			metal.setType(type);
			list.add(metal);
		}
		return list;
	}

	public List<News> getMetals() {
		String metalType = getRequestParam().get("type");
		String jpql = "select n from " + News.class.getSimpleName()
				+ " n where n.tags like '%" + metalType + "%'";
		return query(News.class, jpql, 10);
	}
}
